class Observer{
    constructor(data) {
        this.walk(data)
    }
    walk(data) {
        if(!data || typeof data !== 'object'){
            return
        }
        Object.keys(data).forEach(key=>{
            this.defineReactive(data, key, data[key])
        })
    }
    defineReactive(data, key, value) {
        this.walk(value)
        const _this = this
        const dep = new Dep()
        Object.defineProperty(data, key, {
            enumerable: true,
            configurable: true,
            get() {
                Dep.target = dep.addSub(Dep.target)
                return value
            },
            set(newValue) {
                if(newValue === value){
                    return
                }
                value = newValue
                _this.walk(newValue)
                dep.notfiy()
            }
        })
    }
}